<?php

namespace backend\models\searches;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Registration;

/**
 * RegistrationSearch represents the model behind the search form about `common\models\Registration`.
 */
class RegistrationSearch extends Registration
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'integer'],
            [['invitation_code', 'region', 'dealer', 'dealer_code', 'post', 'name', 'genter', 'card_type', 'card_num', 'telephone', 'nationality', 'email', 'spare_contact', 'spare_contact_phone', 'come_transportation', 'departure_city', 'arrival_location', 'come_flight_number', 'arrival_time', 'is_aircraft', 'back_transportation', 'arrived_city', 'departure_location', 'back_flight_number', 'departure_time', 'is_send', 'dietary_needs', 'is_ceremony', 'is_hotel', 'come_hotel', 'back_hotel', 'forum', 'created_at', 'updated_at', 'deleted_at', 'created_by', 'updated_by', 'deleted_by', 'status'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Registration::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
			'sort' => [
        'defaultOrder' => [
            'created_at' => SORT_DESC,
            'updated_at' => SORT_DESC,
        ]
    ],
        ]);

		//var_dump();
        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'arrival_time' => $this->arrival_time,
            'departure_time' => $this->departure_time,
            'come_hotel' => $this->come_hotel,
            'back_hotel' => $this->back_hotel,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
            'deleted_at' => $this->deleted_at,
        ]);

        $query->andFilterWhere(['like', 'invitation_code', $this->invitation_code])
            ->andFilterWhere(['like', 'region', $this->region])
            ->andFilterWhere(['like', 'dealer', $this->dealer])
            ->andFilterWhere(['like', 'dealer_code', $this->dealer_code])
            ->andFilterWhere(['like', 'post', $this->post])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'genter', $this->genter])
            ->andFilterWhere(['like', 'card_type', $this->card_type])
            ->andFilterWhere(['like', 'card_num', $this->card_num])
            ->andFilterWhere(['like', 'telephone', $this->telephone])
            ->andFilterWhere(['like', 'nationality', $this->nationality])
            ->andFilterWhere(['like', 'email', $this->email])
            ->andFilterWhere(['like', 'spare_contact', $this->spare_contact])
            ->andFilterWhere(['like', 'spare_contact_phone', $this->spare_contact_phone])
            ->andFilterWhere(['like', 'come_transportation', $this->come_transportation])
            ->andFilterWhere(['like', 'departure_city', $this->departure_city])
            ->andFilterWhere(['like', 'arrival_location', $this->arrival_location])
            ->andFilterWhere(['like', 'come_flight_number', $this->come_flight_number])
            ->andFilterWhere(['like', 'is_aircraft', $this->is_aircraft])
            ->andFilterWhere(['like', 'back_transportation', $this->back_transportation])
            ->andFilterWhere(['like', 'arrived_city', $this->arrived_city])
            ->andFilterWhere(['like', 'departure_location', $this->departure_location])
            ->andFilterWhere(['like', 'back_flight_number', $this->back_flight_number])
            ->andFilterWhere(['like', 'is_send', $this->is_send])
            ->andFilterWhere(['like', 'dietary_needs', $this->dietary_needs])
            ->andFilterWhere(['like', 'is_ceremony', $this->is_ceremony])
            ->andFilterWhere(['like', 'is_hotel', $this->is_hotel])
            ->andFilterWhere(['like', 'forum', $this->forum])
            ->andFilterWhere(['like', 'created_by', $this->created_by])
            ->andFilterWhere(['like', 'updated_by', $this->updated_by])
            ->andFilterWhere(['like', 'deleted_by', $this->deleted_by])
            ->andFilterWhere(['like', 'status', $this->status]);

        return $dataProvider;
    }
}
